﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

/// <summary>
/// Summary description for Employee
/// </summary>
public class Employee
{
    static string employeeXml = HttpContext.Current.Server.MapPath(@"Configuration\Employees.xml");

    #region Properties
    int _empID;
    string _fullName;

    public int EmpID
    {
        get
        {
            return _empID;
        }
        set
        {
            _empID = value;
        }
    }

    public string FullName
    {
        get
        {
            return _fullName;
        }
        set
        {
            _fullName = value;
        }
    }
    #endregion Properties

    private Employee()
	{		
	}

    public static List<Employee> GetAllEmployees()
    {
        List<Employee> allEmployees = GetEmployeeDataFromXml(employeeXml);
        return allEmployees;
    }

    private static List<Employee> GetEmployeeDataFromXml(string xmlPath)
    {
        List<Employee> allEmployees = new List<Employee>();
        using (XmlReader reader = XmlReader.Create(xmlPath))
        {
            Employee emp = null;
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case "Employee":
                            emp = new Employee();
                            break;
                        case "EmpID":
                            emp.EmpID = Convert.ToInt32(reader.ReadString());
                            break;
                        case "FullName":
                            emp.FullName = reader.ReadString();
                            allEmployees.Add(emp);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        return allEmployees;
    }
}